/**
* 工程名: 	Quickdisk
* 文件名: 	RegisterAction.java
* 创建人:  	guo.tianxiang
* 创建时间: 	2014-5-6 下午9:50:21
* 版权所有：	Guo Tianxiang 
* 文件描述: 描述该文件的作用
* -----------------------------变更记录 ----------------------------- 
* 日期        		变更人      		版本号  		变更描述  
* ------------------------------------------------------------------  
* 2014-5-6     guo.tianxiang   	1.0       	first created  
*/
package com.tianxiang.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.tianxiang.model.User;
import com.tianxiang.service.UserManagerService;
import com.tianxiang.utils.Tools;

/**
 * 用户注册
 * @since Quickdisk 应用程序版本号
 * @version 1.0 2014-5-6
 * @author guo.tianxiang
 */
public class RegisterAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private UserManagerService service;
	private String username;
	private String password;
	private String nickname;
	private String sex;
	private int age;
	private String phonenum;
	private String email=null;
	private String checkCode;
	private String checkCodeTip;
	
	//管理员信息
	private String superUserName;
	private String superUserPwd;
	
	public String getSuperUserName() {
		return superUserName;
	}

	public void setSuperUserName(String superUserName) {
		this.superUserName = superUserName;
	}

	public String getSuperUserPwd() {
		return superUserPwd;
	}

	public void setSuperUserPwd(String superUserPwd) {
		this.superUserPwd = superUserPwd;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getPhonenum() {
		return phonenum;
	}

	public void setPhonenum(String phonenum) {
		this.phonenum = phonenum;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getCheckCode() {
		return checkCode;
	}

	public void setCheckCode(String checkCode) {
		this.checkCode = checkCode;
	}
	
	public String getCheckCodeTip() {
		return checkCodeTip;
	}

	public void setCheckCodeTip(String checkCodeTip) {
		this.checkCodeTip = checkCodeTip;
	}

	/**
	 * 
	* 管理员注册
	* @return
	 */
public String adminRegister(){
	return SUCCESS;
	
}

public String userRegister(){
	String sessionCheckCode=(String)ActionContext.getContext().getSession().get("CheckCode");
	System.out.println("后台生成的验证码："+sessionCheckCode+"用户输入验证码："+checkCode);
	if (!sessionCheckCode.equalsIgnoreCase(checkCode)) {
		checkCodeTip="验证码错误";
		return "register";
	}
	service=new UserManagerService();
	User user=new User();
	user.setUsername(username);
	System.err.println("pass="+password);
	user.setPassword(Tools.makeMD5(password));
	user.setAge(age);
	user.setEmail(email);
	user.setNickname(nickname);
	user.setPhone(phonenum);
	user.setSex(sex);
	user.setTotalspace(500*1024*1024);			//初始空间为500M
	user.setUsedspace(0);
	 String result=service.userRegister(user);
	 if (result.equals("success")) {
		 Tools.makeuserfile(username);
		 return SUCCESS;
	}
	return result;
}


}
